# -*- coding: utf-8 -*-
'''
Created on 2013-4-10

@author: dyq
'''

from django import  template  
from Common.tool import  tool
from Cms import  settings  
from django.template.loader import get_template
from django.template import Context

register=template.Library()  

def EnumTxt(value,atr):
    return atr[:][value]
register.filter('EnumTxt',EnumTxt)


def length(value):  
    return len(value)
register.filter('length',length)

def tostr(value):  
    return str(value) 
register.filter('tostr',tostr)

def cut(value,atr):  
    return 'abc:' +atr 
register.filter('cut',cut)


def link(value):
    value=settings.PROJECT_PATH_File+value
    
    if settings.DEBUG :
        if str(value).find('?')==-1:
            value+="?rd="+tool.guid()
        else:
            value+="&rd="+tool.guid()
        
    return value

register.filter('link',link)

def Load(value,template):
    '''
          加载其他静态资源
    '''
    t = get_template(template+'.html')
    html = t.render(Context(value))
    return html

register.filter('Load',Load) 

@register.filter
def split(value,splitter):
    return value.split(splitter)

register.filter('split',split) 


@register.filter
def page(value,formid):
    '''
   加载分页控件
    '''
    t = get_template('Common/paginator.html')
    html = t.render(Context({"list":value["list"],"formid":formid,"page_range":value["page_range"]}))
    return html

register.filter('page',page) 



